package bounce;

/**
 * Class to represent a border shape that encapsulates a Shape
 * 
 * @author Ken Neth Yeoh
 *
 */

public class BorderShape extends Shape {
	
	private Shape containedShape;

	public BorderShape(Shape shape) {
		/* create shape object */
		super(shape.x(), shape.y(), shape.deltaX(), shape.deltaY(), shape.width(), shape.height());
		/* keep shape object so we can use it later */
		containedShape = shape;
		/* change values to make a border with a gap of 2 pixels */
		this.fX -= 2;
		this.fY -= 2;
		this.fWidth += 4;
		this.fHeight += 4;
	}
	
	@Override
	public void paint(Painter painter) {
		painter.drawRect(fX, fY, fWidth, fHeight);
	}
	
	public void move(int width, int height) {
		super.move(width, height);
		containedShape.fX = fX + 2;
		containedShape.fY = fY + 2;
	}
	
	public void bounce(int direction) {
		switch(direction) {
		case VERTICAL:
			containedShape.bounce(VERTICAL);
			fDeltaX = -fDeltaX;
			break;
		case HORIZONTAL:
			containedShape.bounce(HORIZONTAL);
			fDeltaY = -fDeltaY;
			break;
		}
	}
}
